package com.atguigu.gmall.item.controller.api;

import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.item.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/***
 * 商品详情页面controller层接口
 */
@RestController
@RequestMapping("/api/item")
public class ApiItemController {

    @Autowired
    private ItemService itemService;

    /**
     * 根据skuId获取商品详情信息
     * @param skuId
     * @return
     */
    @GetMapping("/getSkuInfo/{skuId}")
    public Map getSkuInfo(@PathVariable("skuId") Long skuId){
        //1 校验参数
        if(null == skuId){
            throw new GmallException("参数错误！",null);
        }

        //2 调用业务层方法，获取数据
        Map<String,Object> map = itemService.getSkuInfoDetailBySkyId(skuId);

        //3 响应数据
        return map;
    }
}
